package com.caifu.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Auther: Lyf
 * @Date: 2020/8/3 13:01
 * @Description:
 */
@Configuration
@EnableSwagger2
@PropertySource(value = {"classpath:definition.properties"},encoding = "utf-8")
public class Swagger2Config {

    //swagger-ui.html

    @Value("${swagger.name}")
    private String name;

    @Value("${swagger.url}")
    private String url;

    @Bean
    public Docket createRestApi(){

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(setApiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.caifu.controller")).paths(PathSelectors.any()).build();
    }

    private ApiInfo setApiInfo(){
        return new ApiInfoBuilder().title(name+"api接口文档").contact(new Contact("imooc",url,"caifu@caifu.com")).description("api接口文档详情").version("1.0").termsOfServiceUrl(url).build();
    }
}
